package SingletonMode;

/**
 * @program: DesignModeProject
 * @description: 饿汉模式（静态常量）
 * @author: Li canzhang
 * @create: 2022-04-09 21:29
 **/
public class SingletonTest01 {
    public static void main(String[] args) {
        Singletom01 inst1 = Singletom01.getInst();
        Singletom01 inst2 = Singletom01.getInst();

        System.out.println(inst1.hashCode());
        System.out.println(inst2.hashCode());

    }
}

class Singletom01{
    //构造器私有化
    private Singletom01(){

    }
    //本类中new方法
    private final static Singletom01 inst = new Singletom01();

    //提供一个公共方法获取类实例
    public static Singletom01 getInst(){
        return inst;
    }


}
